#include"include/common.h"
#include<string.h>
#include<stdlib.h>
#include<stdio.h>

//解析命令结构体
int parse_command(const char *input,command *cmd){
    memset(cmd,0,sizeof(command));
    if(strncmp(input,"cd",2) == 0){
        cmd->type = CMD_CD;
        sscanf(input+3,"%s",cmd->arg1);
    }
    else if(strcmp(input, "ls") == 0 || strncmp(input, "ls ", 3) == 0) {
        cmd->type = CMD_LS;
        if (strlen(input) > 2) sscanf(input+3, "%s", cmd->arg1);
    }
    else if(strncmp(input,"puts",4) == 0){
        cmd->type = CMD_PUTS;
        sscanf(input+5,"%s",cmd->arg1);
    }
    else if(strncmp(input,"gets",4) == 0){
        cmd->type = CMD_GETS;
        sscanf(input+5,"%s",cmd->arg1);
    }
    else if(strncmp(input,"remove",6) == 0){
        cmd->type = CMD_REMOVE;
        sscanf(input+7,"%s",cmd->arg1);
    }
    else if(strncmp(input,"pwd",3) == 0){
        cmd->type = CMD_PWD;
    }
    else if(strncmp(input,"mkdir",5) == 0){
        cmd->type = CMD_MKDIR;
        sscanf(input+6,"%s",cmd->arg1);
    }
    else if(strncmp(input,"quit",4) == 0){
        cmd->type = CMD_QUIT;
    }
    else{
        cmd->type = -1;//无法解析命令
    }
}
//释放文件列表
void free_file_list(file_list *head){

}
